﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DNA_Analysis.Models;

namespace DNA_Analysis.Utils
{
    public class Utilities
    {
        private DNAAnalysisEntities db = new DNAAnalysisEntities();

        public Dictionary<string, string> doDnaAnalysis(DNA userDNA)
        {
            // IList<Research> researches = db.Research.ToList<Research>();
            IList<Disease> diseases = db.Disease.ToList<Disease>();
            Dictionary<string, string> dnaReportData = null;

            #region busca por pesquisa
            //if(researches != null && researches.Count != 0)
            //{
            //    dnaReportData = new Dictionary<string, string>();

            //    foreach(Research research in researches)
            //    {
            //        if(userDNA.CompleteDNASequence.Contains(research.DNAPartialPattern))
            //        {
            //            ResearchDiseaseProbability diseaseResearch = db.ResearchDiseaseProbability.First(r => r.Research_Id == research.Id);
            //            string diseaseName = db.Disease.First(d => d.Id == diseaseResearch.Disease_Id).Name;
            //            dnaReportData.Add(diseaseName, diseaseResearch.Probability);
            //        }
            //    }
            //}
            #endregion

            if(diseases != null && diseases.Count != 0)
            {
                dnaReportData = new Dictionary<string, string>();
                foreach(Disease disease in diseases)
                {
                    ResearchDiseaseProbability rdp = db.ResearchDiseaseProbability.First(rd => rd.Disease_Id == disease.Id);
                    Research research = db.Research.First(r => r.Id == rdp.Research_Id);
                    if(userDNA.CompleteDNASequence.Contains(research.DNAPartialPattern))
                    {
                        dnaReportData.Add(disease.Name, Math.Round(rdp.Probability, 2).ToString() + "%");
                    }
                    else
                    {
                        dnaReportData.Add(disease.Name, "N/A");
                    }
                }
            }

            return dnaReportData;
        }
    }
}